#include "title.h"
#include "ui_title.h"

#include <QDebug>
#include<QPainter>
title::title(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::title)
{
    ui->setupUi(this);
    this->background.load(":/new/prefix1/res/titlecolor1.png");
    ui->icon->setPixmap(QPixmap(":/new/prefix1/res/icon.png"));

    //关闭窗口
    ui->windowclose->setFixedSize(40,40);
    ui->windowclose->setpicture(":/new/prefix1/res/close1(1).png",
                                ":/new/prefix1/res/close.png",
                                ":/new/prefix1/res/close1(1).png");
    //放大缩小窗口
    ui->windowminormax->setFixedSize(40,40);
    ui->windowminormax->setpicture(":/new/prefix1/res/min2(1).png"
                                   ,":/new/prefix1/res/min1.png",
                                   "qrc:/new/prefix1/res/min2(1).png");
    //最小化窗口
    ui->windowmin->setFixedSize(50,50);
    ui->windowmin->setpicture(":/new/prefix1/res/min2.png"
                              ,":/new/prefix1/res/min3.png",
                              ":/new/prefix1/res/min2.png");
}
title::~title()
{
    delete ui;
}

void title::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.drawPixmap(rect(),this->background);
    update();
}

void title::on_windowclose_clicked()
{
    emit myclose();
}

void title::on_windowminormax_clicked()
{
    emit this->changewindow(this->flag);
    this->flag=!flag;
}
void title::mousePressEvent(QMouseEvent *event){
     last = event->globalPos();
}

void title::mouseMoveEvent(QMouseEvent *event){
    int dx = event->globalX() - last.x();
    int dy = event->globalY() - last.y();
    last = event->globalPos();
    emit  this->WindowMove(QPoint(dx,dy));
}

void title::on_windowmin_clicked()
{
    emit this->Windowmin();
}
